﻿@namespace Bit.BlazorUI
@inherits BitComponentBase

<div @ref="RootElement" @attributes="HtmlAttributes"
     id="@_Id"
     class="@ClassBuilder.Value"
     style="@StyleBuilder.Value"
     dir="@Dir?.ToString().ToLower()">

    @foreach (var item in _items)
    {
        <div @key="item.Id"
             style="@Styles?.Container @item.CssStyle"
             class="bit-snb-itm @GetItemClasses(item) @Classes?.Container @item.CssClass">
            <div style="@Styles?.Header" class="bit-snb-hdr @Classes?.Header">
                @if (Persistent is false && item.Persistent is false)
                {
                    <button @onclick="() => Dismiss(item)"
                            type="button"
                            style="@Styles?.DismissButton"
                            class="bit-snb-cbt @Classes?.DismissButton">
                        <i style="@Styles?.DismissIcon" class="bit-icon bit-icon--@(DismissIconName ?? "Cancel") @Classes?.DismissIcon" />
                    </button>
                }

                @if (TitleTemplate is not null)
                {
                    @TitleTemplate(item.Title)
                }
                else if (item.Title.HasValue())
                {
                    <label title="@item.Title"
                           style="@Styles?.Title"
                           class="bit-snb-ttl @(Multiline ? "" : "bit-snb-elp") @Classes?.Title">
                        @item.Title
                    </label>
                }
            </div>

            @if (BodyTemplate is not null)
            {
                @BodyTemplate(item.Body ?? string.Empty)
            }
            else if (item.Body.HasValue())
            {
                <div style="@Styles?.Body"
                     class="bit-snb-bdy @(Multiline ? "" : "bit-snb-elp") @Classes?.Body">
                    @item.Body
                </div>
            }

            @if (AutoDismiss)
            {
                <span style="animation-duration:@GetDuration(); @Styles?.ProgressBar"
                      class="bit-snb-prb @Classes?.ProgressBar">
                </span>
            }
        </div>
    }
</div>